package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/12 14:50
 */
public class M0803 {

    // https://leetcode-cn.com/problems/magic-index-lcci/
    public static int findMagicIndex(int[] nums) {
        for (int i = 0; i < nums.length; )
            if (i == nums[i]) return i;
            else i = Math.max(nums[i], i + 1);
        return -1;
    }


    // for test
    public static void main(String[] args) {
        int[] nums = {1, 1, 1};
        System.out.println(findMagicIndex(nums));
    }

}
